using UnityEngine;
using System.Collections;

public enum MarbleGameState{playing,won,lost};

public class MarbleManager : MonoBehaviour 
{
	public static MarbleManager SP;
	
	private int totalGems;
	private int foundGems;
	
	private MarbleGameState gameState;
	
	
	void Awake()
	{
		SP = this;
		foundGems = 0;
		gameState = MarbleGameState.playing;
		totalGems = GameObject.FindGameObjectsWithTag("Pickup").Length;
		Time.timeScale = 1.0f;
	}
	
	public void FoundGem()
	{
		foundGems++;
		if (foundGems >= totalGems)
		{
			WonGame();	
		}
	}
	public void WonGame()
	{
		Time.timeScale = 0.0f;//pause game
		gameState = MarbleGameState.won;
	}
	
	public void SetGameOver()
	{
		Time.timeScale = 0.0f;
		gameState = MarbleGameState.lost;
	}
	
	void OnGUI()
	{
		GUILayout.Label("Gemas: "+ foundGems +"/"+totalGems);
		if(gameState == MarbleGameState.lost)
		{
			GUILayout.Label("Perdeu!");
			if(GUILayout.Button("Tentar de novo"))
			{
				Application.LoadLevel(Application.loadedLevel);	
			}
			
		}
		else if(gameState == MarbleGameState.won)
		{
			GUILayout.Label("Ganhou!");
			if(GUILayout.Button("Tentar de novo"))
			{
				Application.LoadLevel(Application.loadedLevel);	
			}
		}
	}
	
	
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}
